package com.qingcheng.consumer;

import com.alibaba.fastjson.JSON;
import com.qingcheng.pojo.order.OrderItem;
import com.qingcheng.service.goods.StockBackService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Author: LDeng
 * @Date: 2020-07-03 11:48
 */
public class BackMessageConsumer implements MessageListener {

    @Autowired
    private StockBackService stockBackService;


    @Override
    public void onMessage(Message message) {
        //提取消息
        try {
            String jsonString = new String(message.getBody());
            List<OrderItem> orderItemList = JSON.parseArray(jsonString, OrderItem.class);
            stockBackService.addList(orderItemList);
        } catch (Exception e) {
            e.printStackTrace();
            //记录日志， 之后人工干预


        }


    }
}
